package v1

import (
    "ginblog/model"
    "ginblog/model/response"
    "github.com/gin-gonic/gin"
    "strconv"
)

// 添加用户
func UserExist(c *gin.Context) {

}
func Edit(c *gin.Context) {

}
func GetUsers(c *gin.Context) {
    pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize","10"))
    pageNum, _ := strconv.Atoi(c.DefaultQuery("pageNum","1"))
    // todo 参数校验
    data,err := model.GetUsers(pageSize,pageNum)
    if err != nil {
        response.Fail(c,model.DB_ERROR,nil)
    }
    response.Ok(c,data)
}
// @Summary 用户相关接口
// @Description 添加用户
// @Tags 帖子相关接口
// @Accept application/json
// @Produce application/json
// @Security ApiKeyAuth
// @Success 200 {object} response.Res
// @Router /posts2 [get]
func AddUser(c *gin.Context) {
    var (
        code model.Code
        u    model.User
    )
    _ = c.ShouldBindJSON(&u)
    // todo 参数校验
    if code = u.CheckUser(); code == model.SUCCESS {
        if code = u.Create(); code == model.ERROR {
            response.Fail(c, model.ERROR, u)
            return
        }
    } else {
        response.Fail(c, code, u)
        return
    }
    response.Ok(c, u)
}
func DeleteUser(c *gin.Context) {

}
